import Flutter
import Foundation

public class TlcLockPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "tlc_lock", binaryMessenger: registrar.messenger())
    let instance = TlcLockPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)

    let scanChannel = FlutterEventChannel(name: "tlc_lock/scan", binaryMessenger: registrar.messenger())
    scanChannel.setStreamHandler(Manager.shared)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    switch call.method {
    case "getPlatformVersion":
      result("iOS " + UIDevice.current.systemVersion)
    case "test":
        Manager.shared.test()
    case "connect":
        guard let identifier = call.arguments as? String, !identifier.isEmpty else {
            result("identifier not found")
            return
        }
        Manager.shared.connect(identifier, result: result)
    default:
      result(FlutterMethodNotImplemented)
    }
  }
}
